package com.hdey.controller.max;

import com.hdey.pojo.max.TbUscDictionary;
import com.hdey.service.max.TbUscDictionarySvs;
import com.hdey.utils.Result;
import com.hdey.vo.DictionaryForSearch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dictionary")
@Slf4j
public class TbUscDictionaryController {

    @Resource
    private TbUscDictionarySvs dictionarySvs;

    private String msg;


    @RequestMapping("/getDictionary")
    public Result getDictionary(DictionaryForSearch dictionary){
        List<TbUscDictionary> list = dictionarySvs.getTbUscDictionary(dictionary);
        return Result.success(list,list.size());
    }

    @RequestMapping("/createDictionary")
    public Result createDictionary(@RequestBody TbUscDictionary dictionary){

        Integer result = dictionarySvs.createTbUscDictionary(dictionary);
        if(result > 0){
            msg = "创建成功！";
        }else{
            msg = "系统错误！";
        }
        return Result.success(msg);
    }


    @RequestMapping("/updateDictionary")
    public Result updateDictionary(@RequestBody TbUscDictionary dictionary){

        Integer result = dictionarySvs.updateTbUscDictionary(dictionary);
        if(result > 0){
            msg = "修改成功！";
        }else{
            msg = "系统错误！";
        }
        return Result.success(msg);
    }


    @RequestMapping("/deleteDictionary")
    public Result deleteDictionary(Integer dictionaryId){

        Integer result = dictionarySvs.deleteTbUscDictionary(dictionaryId);
        if(result > 0){
            msg = "删除成功！";
        }else{
            msg = "系统错误！";
        }
        return Result.success(msg);
    }

}
